/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.uuid.UUIDGenerator;
import cn.qidisoft.edu.hzjt.dao.ZxjStudentNationalGrantMapper;
import cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant;
import cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: BjxxClassMaterialProjectServiceImpl.java, v 0.1 2018年10月29日 下午1:14:36 hhl Exp $
 */
@Service("zxjStudentNationalGrantService")
public class ZxjStudentNationalGrantServiceImpl implements IZxjStudentNationalGrantService {

    protected static final LoggerAdapter  LOGGER = LoggerAdapterFactory
        .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    private ZxjStudentNationalGrantMapper zxjStudentNationalGrantMapper;

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryList(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public List<ZxjStudentNationalGrant> queryList(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.queryList(data);

        } catch (Exception e) {
            LOGGER.error("queryList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryByPK(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public ZxjStudentNationalGrant queryByPK(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.queryByPK(data);
        } catch (Exception e) {
            LOGGER.error("queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#add(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public String add(ZxjStudentNationalGrant data) {
        String uuid = UUIDGenerator.genReqID();
        try {
            data.setGid(uuid);
            zxjStudentNationalGrantMapper.add(data);
        } catch (Exception e) {
            LOGGER.error("add [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
        return uuid;
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#update(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public int update(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.update(data);
        } catch (Exception e) {
            LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#delete(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void delete(ZxjStudentNationalGrant data) {
        try {
            zxjStudentNationalGrantMapper.delete(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryPageList(cn.qidisoft.microClass.resource.model.basis.Catalog,
     *      cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<ZxjStudentNationalGrant> queryPageList(ZxjStudentNationalGrant data,
                                                                 Page page) {
        try {

            int c = zxjStudentNationalGrantMapper.queryPageListcount(data);
            int totalRecords = 0;
            totalRecords = (int) c;
            PaginationBean<ZxjStudentNationalGrant> pageHolder = new PaginationBean<ZxjStudentNationalGrant>(
                page, totalRecords);
            List<ZxjStudentNationalGrant> resultList = zxjStudentNationalGrantMapper.queryPageList(
                data, new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#validation(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public int validation(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.validation(data);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }
    }

    /**
     * @see cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService#queryPageList_admin(cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant,
     *      cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<ZxjStudentNationalGrant> queryPageList_admin(ZxjStudentNationalGrant data,
                                                                       Page page) {
        try {

            int c = zxjStudentNationalGrantMapper.queryPageListcount_admin(data);
            int totalRecords = 0;
            totalRecords = (int) c;
            PaginationBean<ZxjStudentNationalGrant> pageHolder = new PaginationBean<ZxjStudentNationalGrant>(
                page, totalRecords);
            List<ZxjStudentNationalGrant> resultList = zxjStudentNationalGrantMapper
                .queryPageList_admin(data,
                    new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                        pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService#auditList(cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant)
     */
    @Override
    @Transactional
    public void auditList(ZxjStudentNationalGrant data) {
        try {
            for (String s : data.getIds()) {
                /* ZxjStudentNationalGrant data1 = new ZxjStudentNationalGrant(); */
                data.setSqid(Integer.valueOf(s));
                /*
                 * data1.setStates(data.getStates()); data1.setAudittime(data.getAudittime());
                 * data1.setAuditorid(data.getAuditorid()); data1.setAuditsuggestion(null);
                 */
                zxjStudentNationalGrantMapper.auditList(data);
            }
        } catch (Exception e) {
            LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /**
     * @see cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService#queryStudentNationalGrantCount(cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant)
     */
    @Override
    public int queryStudentNationalGrantCount(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.queryStudentNationalGrantCount(data);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(
                "queryStudentNationalGrantCount [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService#audit(cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant)
     */
    @Override
    public int audit(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.audit(data);
        } catch (Exception e) {
            LOGGER.error("audit [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.IZxjStudentNationalGrantService#export(cn.qidisoft.edu.hzjt.model.ZxjStudentNationalGrant)
     */
    @Override
    public List<ZxjStudentNationalGrant> export(ZxjStudentNationalGrant data) {
        try {
            return zxjStudentNationalGrantMapper.export(data);
        } catch (Exception e) {
            LOGGER.error("audit [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

}
